/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.fandi.model;

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Fandy
 */
public class ItemTableModel extends AbstractTableModel {
    private List<ItemModel> list;

    public ItemTableModel() {
        list = new ArrayList<>();
    }
    
    public void setList(List<ItemModel> list) {
        this.list = list;
        fireTableDataChanged();
    }
    
    @Override
    public int getRowCount() {
        return list.size();
    }

    @Override
    public int getColumnCount() {
        return 4;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch(columnIndex) {
            case    0 :
                return list.get(rowIndex).getCode();
            case    1 :
                return list.get(rowIndex).getName();
            case    2 :
                return list.get(rowIndex).getQty();
            case    3 :
                return list.get(rowIndex).getExpired();
            default   :
                return null;
        }
    }
    
    @Override
    public String getColumnName(int columnIndex) {
        switch(columnIndex) {
            case    0 :
                return "Code";
            case    1 :
                return "Item Name";
            case    2 :
                return "QTY";
            case    3 :
                return "Expired Date";
            default   :
                return null;
        }
    }
    
    
}
